//
//  YQNewFeatureViewController.m
//  WeiboOC
//
//  Created by yang on 15/11/16.
//  Copyright © 2015年 yang. All rights reserved.
//

#import "YQNewFeatureViewController.h"

@interface YQNewFeatureViewController ()

@end

@implementation YQNewFeatureViewController
static int imageCount = 4;
static NSString * const reuseIdentifier = @"Cell";
-(instancetype)init{
    return [self loadLayout];
}
-(instancetype)loadLayout{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = [UIScreen mainScreen].bounds.size;
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 0;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    return [super initWithCollectionViewLayout:layout];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.collectionView.pagingEnabled = YES;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    self.collectionView.bounces = NO;
    [self.collectionView registerClass:[YQNewFeatureCell class] forCellWithReuseIdentifier:reuseIdentifier];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return imageCount;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    YQNewFeatureCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    cell.index = indexPath.item;
    return cell;
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    NSInteger page = scrollView.contentOffset.x / screenW ;
    if (page == imageCount - 1) {
       YQNewFeatureCell *cell = (YQNewFeatureCell *)[self.collectionView visibleCells].lastObject;
        [cell.startButton addTarget:self action:@selector(start) forControlEvents:UIControlEventTouchUpInside];
        [cell startAnimation];
    }
}
- (void)start{
    [[NSNotificationCenter defaultCenter] postNotificationName:AppSwitchRootViewControler object:nil];
}
@end
